package com.ding.demo.service;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzMain {


    public static void main(String[] args) throws SchedulerException, InterruptedException {

        //定义一个JobDetail
        JobDetail jobDetail = JobBuilder.newJob(HelloQuartz.class)
                //定义name和group
                .withIdentity("job1", "group1")
                //job需要传递的内容
                .usingJobData("name", "sdas")
                .build();
        //定义一个Trigger
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
                //加入 scheduler之后立刻执行
                .startNow()
                //定时 ，每个1秒钟执行一次
                .withSchedule(CronScheduleBuilder.cronSchedule("*/5 * * * * ?")).build();


        //创建scheduler
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start(); //运行一段时间后关闭

        Thread.sleep(60000);

        scheduler.shutdown();
    }


}


